package com.whut.report;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.whut.mapper.NewPrefixSystemMapper;
import com.whut.model.*;
import com.whut.parMapper.ParProblemCollectDetailMapper;
import com.whut.parMapper.ParProblemDescriptionMapper;
import com.whut.parMapper.ParSystemMapper;
import com.whut.parMapper.utils.MapperUtils;
import com.whut.service.impl.ReportServiceImpl;
import com.whut.utils.FileUtil;
import com.whut.utils.MDoc;
import com.whut.utils.pointsCalculate;
import com.whut.v_model.ProblemCollectDetail;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

import com.whut.common.ReportCommonFunc;
import javax.annotation.Resource;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;

/**
 * @author ：xiaojun
 * @date ：Created in 2021/4/20 21:16
 * @description：
 * @modified By：
 * @version: $
 */
public class ConstructionMulCheckReport {
    private ParSystemMapper parSystemMapper;
    private ParProblemDescriptionMapper parProblemDescriptionMapper;
    private ParProblemCollectDetailMapper parProblemCollectDetailMapper;
    private ReportServiceImpl reportServiceImpl;
    @Resource
    private UrlProperties urlProperties;
    @Resource
    private Profiles profiles;
    private MapperUtils mapperUtils;

    private int checkId;
    private int projectId;
    private boolean isNew;
    public static final int WIDTH = 718;
    public static final int HEIGHT = 468;
    public ConstructionMulCheckReport(ParSystemMapper parSystemMapper,
                                      ParProblemDescriptionMapper parProblemDescriptionMapper,
                                      ParProblemCollectDetailMapper parProblemCollectDetailMapper,
                                      ReportServiceImpl reportServiceImpl,
                                      MapperUtils mapperUtils,
                                      UrlProperties urlProperties,
                                      Profiles profiles){
        this.parSystemMapper = parSystemMapper;
        this.parProblemDescriptionMapper = parProblemDescriptionMapper;
        this.parProblemCollectDetailMapper = parProblemCollectDetailMapper;
        this.reportServiceImpl = reportServiceImpl;
        this.mapperUtils=mapperUtils;
        this.urlProperties=urlProperties;
        this.urlProperties=urlProperties;
        this.profiles=profiles;
    }


    public String generateWord(int checkId, int projectId) throws UnsupportedEncodingException {
        initWordTheme();

        DecimalFormat df = new DecimalFormat("0.00");

        Map<String, Object> dataMap = new HashMap<String, Object>();

        initWordDate(dataMap);
        if (parSystemMapper instanceof NewPrefixSystemMapper){
            System.out.println(true);
            String zlWeight = parSystemMapper.getWeight1ByName1("新质量检查");
            String aqWeight = parSystemMapper.getWeight1ByName1("新安全检查");
            String glWeight = parSystemMapper.getWeight1ByName1("新管理行为");
            dataMap.put("zlWeight", zlWeight);
            dataMap.put("aqWeight", aqWeight);
            dataMap.put("glWeight", glWeight);
        }else {
            String zlWeight = parSystemMapper.getWeight1ByName1("质量检查");
            String aqWeight = parSystemMapper.getWeight1ByName1("安全检查");
            String glWeight = parSystemMapper.getWeight1ByName1("管理行为");
            dataMap.put("zlWeight", zlWeight);
            dataMap.put("aqWeight", aqWeight);
            dataMap.put("glWeight", glWeight);
        }
        dataMap.put("zlPoint", "\\");
        dataMap.put("glPoint", "\\");
        dataMap.put("aqPoint", "\\");
        dataMap.put("zlLever", "\\");
        dataMap.put("aqLever", "\\");
        dataMap.put("glLever", "\\");
        //工程概况部分，来自ctp的工程信息
        reportServiceImpl.initProjectSummaryFirstPart(projectId, dataMap);
        //工程概况部分，来自设备信息表的设备信息部分
        List<Equipinfo> equipinfoList = mapperUtils.getEquipinfoMapper().getAllByProjectId(projectId);
        String equip = JSON.toJSONString(equipinfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray equipArray = JSONArray.parseArray(equip);
        List<Object> equipList = new ArrayList<Object>();
        if (equipArray.size() == 0) {
            Map<String, Object> eqMap = new HashMap<String, Object>();
            eqMap.put("equipType", "\\");
            eqMap.put("equipQua", "\\");
            eqMap.put("equipNum", "\\");
            eqMap.put("equipLeaseUnit", "\\");
            eqMap.put("equipUseUnit", "\\");
            eqMap.put("demolitionUnit", "\\");
            eqMap.put("testUnit", "\\");
            equipList.add(eqMap);
        } else {
            for (int i = 0; i < equipArray.size(); i++) {
                Map<String, Object> eqMap = new HashMap<String, Object>();
                JSONObject equipObject = equipArray.getJSONObject(i);
                eqMap.put("equipType", equipObject.getString("equipType"));
                eqMap.put("equipQua", equipObject.getString("equipQua"));
                eqMap.put("equipNum", equipObject.getString("equipNum"));
                eqMap.put("equipLeaseUnit", equipObject.getString("equipLeaseUnit"));
                eqMap.put("equipUseUnit", equipObject.getString("equipUseUnit"));
                eqMap.put("demolitionUnit", equipObject.getString("demolitionUnit"));
                eqMap.put("testUnit", equipObject.getString("testUnit"));
                equipList.add(eqMap);
            }
        }
        dataMap.put("equipList", equipList);
        //第一部分，综合评估结果，从合同任务检查表中获取相关信息,签名部分
        List<ContractCheckTask> checkInfo = mapperUtils.getContractchecktaskMapper().getCheckInfoByCheckId(checkId);
        String check = JSON.toJSONString(checkInfo, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray checkArray = JSONArray.parseArray(check);
        JSONObject checkObject = checkArray.getJSONObject(0);

//        dataMap.put("jsSign", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png"));
//        dataMap.put("jlSign", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png"));
//        dataMap.put("sgSign", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png"));
        String signPicPath = checkObject.getString("signPath");
        String jsSign = checkObject.getString("jsSign");
        String jlSign = checkObject.getString("jlSign");
        String sgSign = checkObject.getString("sgSign");
        if (signPicPath == null || signPicPath.equals("")) {
            dataMap.put("jsSign", MDoc.getImageStr("D:\\whutServer\\generatedCharts\\blank.png"));
            dataMap.put("jlSign", MDoc.getImageStr("D:\\whutServer\\generatedCharts\\blank.png"));
            dataMap.put("sgSign", MDoc.getImageStr("D:\\whutServer\\generatedCharts\\blank.png"));
        } else {
            dataMap.put("jsSign", MDoc.getImageStr(signPicPath + jsSign));
            dataMap.put("jlSign", MDoc.getImageStr(signPicPath + jlSign));
            dataMap.put("sgSign", MDoc.getImageStr(signPicPath + sgSign));
        }
        /*改写分项评估结果*/

        //第一部分，（二）分项评估结果
        Integer taskId = mapperUtils.getContractchecktaskMapper().getTaskIdByCheckId(checkId);
        List<Integer> pName1Info = parProblemCollectDetailMapper.getAllName1Id(checkId);
        String name1 = JSON.toJSONString(pName1Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray name1Array = JSONArray.parseArray(name1);   //firstId
        float allExtraPointFloat = parProblemCollectDetailMapper.getAllExtraPoint(checkId);
        double allExtraPoint = Double.valueOf(String.valueOf(allExtraPointFloat));
        double overAllPoint = 0;
        List<Object> part2List = new ArrayList<Object>();
        String Name1 = "";
        double allweight1 = 0;
        //质量和安全对调
        int securitySort = 0;
        int quilitySort = 0;
        for (int i = 0; i < name1Array.size(); i++) {
            double Tweight1 = 0;
            String weight1 = parSystemMapper.getWeight1ByName1(parSystemMapper.getName4ByName4Id(name1Array.getIntValue(i)));
            Tweight1 = pointsCalculate.getPercentInstance(weight1);
            allweight1 += Tweight1;
            if (name1Array.getIntValue(i) == 1) {
                securitySort = i;
            } else if (name1Array.getIntValue(i) == 628) {
                quilitySort = i;
            }
        }
        if (securitySort != 0 || quilitySort != 0) {
            Collections.swap(name1Array, securitySort, quilitySort);
        }
        for (int k = 0; k < name1Array.size(); k++) {
            Map<String, Object> part2Map = new HashMap<String, Object>();
            List<Object> part2InnerList = new ArrayList<Object>();
            String pName1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(k)); //通过firstId找到pName1
            double Tweight1 = 0;
            String weight1 = parSystemMapper.getWeight1ByName1(pName1);  //获取权重
            Tweight1 = pointsCalculate.getPercentInstance(weight1);
            if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                String aqLever=" ";
                switch(Integer.parseInt(pointsCalculate.getMaxRiskPoint(list))){
                    case 4:
                        aqLever="一级隐患";
                        break;
                    case 3:
                        aqLever="二级隐患";
                        break;
                    case 2:
                        aqLever="三级隐患";
                        break;
                    case 1:
                        aqLever="四级隐患";
                        break;
                }
                dataMap.put("aqLever", aqLever);
                Name1 = "安全文明";
            } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                String zlLever=" ";
                switch(Integer.parseInt(pointsCalculate.getMaxRiskPoint(list))){
                    case 4:
                        zlLever="一级隐患";
                        break;
                    case 3:
                        zlLever="二级隐患";
                        break;
                    case 2:
                        zlLever="三级隐患";
                        break;
                    case 1:
                        zlLever="四级隐患";
                        break;
                }
                dataMap.put("zlLever", zlLever);
                Name1 = "质量风险";
            } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                String glLever=" ";
                switch(Integer.parseInt(pointsCalculate.getMaxRiskPoint(list))){
                    case 4:
                        glLever="一级隐患";
                        break;
                    case 3:
                        glLever="二级隐患";
                        break;
                    case 2:
                        glLever="三级隐患";
                        break;
                    case 1:
                        glLever="四级隐患";
                        break;
                }
                dataMap.put("glLever", glLever);
                Name1 = "管理行为";
            }
            part2Map.put("name1No", k + 1);
            part2Map.put("name1", Name1);
            List<Object> secondIdList = parProblemCollectDetailMapper.getSecondId(checkId, pName1);  //获取secondIdList
            String secondIdInfo = JSON.toJSONString(secondIdList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray secondIdInfoArray = JSONArray.parseArray(secondIdInfo);
            double allweight2 = 0;
            for (int p = 0; p < secondIdInfoArray.size(); p++) {
                int allsecondId = secondIdInfoArray.getIntValue(p);
                String weight2 = parSystemMapper.getWeight3ByThirdId(allsecondId);
                double weight22 = pointsCalculate.getPercentInstance(weight2);
                allweight2 += weight22;
            }
            double allsecondPoint = 0;
            for (int u = 0; u < secondIdInfoArray.size(); u++) {
                int secondId = secondIdInfoArray.getIntValue(u);
                double weight222 = 0;
                String weight2 = parSystemMapper.getWeight3ByThirdId(secondId); //获取第三级权重的weight
                weight222 = pointsCalculate.getPercentInstance(weight2);
                double point = 0;

                List<ProblemCollectDetail> fourthPoints = parProblemCollectDetailMapper.getFourthPoint(checkId, pName1, secondId);
                String fourthCalculateInfo = JSON.toJSONString(fourthPoints, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray fourthPointsCalculateArray = JSONArray.parseArray(fourthCalculateInfo);

                //添加无问题项
                List<ProblemCollectDetail> noProblemItemList = new ArrayList<>();
                List<Noproblemitem> noProblemFourthId= mapperUtils.getNoproblemitemMapper().getFourthIdList(checkId,secondId);
                for (Noproblemitem noproblemitem : noProblemFourthId){
                    ProblemCollectDetail pcd = new ProblemCollectDetail();
                    pcd.setFourthId(noproblemitem.getFourthId());
                    pcd.setThirdId(noproblemitem.getThirdId());
                    String weight3= parSystemMapper.getWeight3ByThirdId(noproblemitem.getThirdId());
                    String weight4= parSystemMapper.getWeight3ByThirdId(noproblemitem.getFourthId());
                    pcd.setWeight3(weight3);
                    pcd.setWeight4(weight4);
                    String pName4 = parSystemMapper.getName4ByName4Id(noproblemitem.getFourthId());
                    pcd.setpName4(pName4);
                    pcd.setPoint3(parSystemMapper.getPoint4ByPoint4Id(noproblemitem.getThirdId()));
                    pcd.setPoint4(parSystemMapper.getPoint4ByPoint4Id(noproblemitem.getFourthId()));
                    noProblemItemList.add(pcd);
                }
//                List<ProblemCollectDetail> noProblemItemList = parProblemCollectDetailMapper.getNoProblemItem(checkId, secondId);
                String noProblemCalculateInfo = JSON.toJSONString(noProblemItemList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray noProblemCalculateArray = JSONArray.parseArray(noProblemCalculateInfo);
                for (int j = 0; j < noProblemCalculateArray.size(); j++) {
                    Map<String, Object> part2InnerMap = new HashMap<String, Object>();
                    JSONObject part2InnerObject = noProblemCalculateArray.getJSONObject(j);
                    Double point4=Double.parseDouble(part2InnerObject.getString("point4"));
                    point += point4*pointsCalculate.getPercentInstance(part2InnerObject.getString("weight3"));
                    part2InnerMap.put("pName4", noProblemItemList.get(j).getpName4());
                    part2InnerMap.put("weight4",part2InnerObject.getString("weight3"));
                    part2InnerMap.put("checkItemPoint", part2InnerObject.getString("point4"));
                    part2InnerList.add(part2InnerMap);
                }
                for (int j = 0; j < fourthPointsCalculateArray.size(); j++) {
                    Map<String, Object> part2InnerMap = new HashMap<String, Object>();
                    JSONObject part2InnerObject = fourthPointsCalculateArray.getJSONObject(j);
                    part2InnerMap.put("pName4", part2InnerObject.getString("pName4"));

                    double allweight4 = this.calculateAllWeight4Func(checkId, part2InnerObject, taskId, isNew);
                    double weight3 = 0;
                    double weight4 = 0;
                    int part2FourthId = part2InnerObject.getIntValue("fourthId");
                    int part2ThirdId = part2InnerObject.getIntValue("thirdId");
                    //更改权重来源
                    String newWeight4 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(part2FourthId, taskId);
                    if (StringUtils.isNotBlank(newWeight4)) {
                        weight4 = pointsCalculate.getPercentInstance(newWeight4);
                    } else {
                        weight4 = pointsCalculate.getPercentInstance(part2InnerObject.getString("weight4"));
                    }

                    String newWeight3 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(part2ThirdId, taskId);
                    if (StringUtils.isNotBlank(newWeight3)) {
                        weight3 = pointsCalculate.getPercentInstance(newWeight3);
                    } else {
                        weight3 = pointsCalculate.getPercentInstance(part2InnerObject.getString("weight3"));
                    }

                    String weight4Result = this.getPart2InnerListweight4(checkId, part2ThirdId, weight3, weight4, allweight4);
                    part2InnerMap.put("weight4", weight4Result);

                    List<ProblemCollectDetail> sixthPoints = parProblemCollectDetailMapper.getsixthPoints(checkId, part2FourthId);
                    String pointName6Info = JSON.toJSONString(sixthPoints, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                    JSONArray sixthPointsArray = JSONArray.parseArray(pointName6Info);
                    double calculatePoint6 = 0;
                    double calculateTruePoint = 0;
                    List<Double> calculatePointList = this.calculatePoint6Func(sixthPointsArray, checkId, isNew);
                    calculatePoint6 = calculatePointList.get(1);
                    calculateTruePoint = calculatePointList.get(0);
                    double noProblemPoint = this.calculateNoProblemPointFunc(checkId, part2InnerObject,isNew);
                    System.out.println("第六级扣过的分数总分:" + calculatePoint6 + "没有问题的总分:" + noProblemPoint + "第六级总分:" + calculateTruePoint);
                    double checkItemPoint = (calculatePoint6 + noProblemPoint) / (calculateTruePoint + noProblemPoint) * 100;
                    String s = this.getCheckItemPointAndUpdateAllPointSave(checkId, part2FourthId, projectId, checkItemPoint, df);

                    part2InnerMap.put("checkItemPoint", s);
                    point += checkItemPoint * weight3 / (allweight4 / weight4);
                    part2InnerList.add(part2InnerMap);
                }

                List<Object> getThirdId = parProblemCollectDetailMapper.getThirdId(checkId, pName1, secondId);
                String thirdIdInfo = JSON.toJSONString(getThirdId, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray thirdArray = JSONArray.parseArray(thirdIdInfo);
                /*thirdArray中还需要加入无问题项的内容*/
                List<Object> noProblemThirdId= mapperUtils.getNoproblemitemMapper().getThirdIdList(checkId,secondId);
                for (Object obj : noProblemThirdId){
                    thirdArray.add(obj);
                }
                double allweight3 = 0;
                for (int v = 0; v < thirdArray.size(); v++) {
                    double Tweight3 = 0;
                    int thirdId = thirdArray.getIntValue(v);
                    String newWeight3 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(thirdId, taskId);
                    if (StringUtils.isNotBlank(newWeight3)) {
                        Tweight3 = pointsCalculate.getPercentInstance(newWeight3);
                    } else {
                        String trueweight3 = parSystemMapper.getWeight3ByThirdId(thirdId);
                        Tweight3 = pointsCalculate.getPercentInstance(trueweight3);
                    }
                    allweight3 += Tweight3;
                }
                System.out.println(point + "dasdasdadasd" + allweight3 + "dasdsadsadad" + df.format(point / allweight3));
                double thirdPoint = Double.parseDouble(df.format(point / allweight3));
                double percent2 = Double.parseDouble(df.format(weight222 / allweight2));
                double secondPoint = Double.parseDouble(df.format(thirdPoint * percent2));
                allsecondPoint += secondPoint;
            }

            if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                dataMap.put("aqPoint", allsecondPoint);
            } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                dataMap.put("zlPoint", allsecondPoint);
            } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                dataMap.put("glPoint", allsecondPoint);
            }
            int firstPointCount = mapperUtils.getAllpointsaveMapper().getAllPointCountByCheckId(checkId, name1Array.getInteger(k));
            if (firstPointCount != 0) {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date1 = new Date(System.currentTimeMillis());
                String lastEditTime = formatter.format(date1);
                mapperUtils.getAllpointsaveMapper().updateAllPoint(checkId, df.format(allsecondPoint), name1Array.getInteger(k), lastEditTime);
            } else {
                Allpointsave allpointsave = new Allpointsave();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date1 = new Date(System.currentTimeMillis());
                allpointsave.setNewCreateTime(formatter.format(date1));
                allpointsave.setLastEditTime(formatter.format(date1));
                allpointsave.setCheckId(checkId);
                allpointsave.setNumber(name1Array.getInteger(k));
                allpointsave.setPoint(df.format(allsecondPoint));
                allpointsave.setProjectId(projectId);
                mapperUtils.getAllpointsaveMapper().insert(allpointsave);
            }
            //提前使用Double.parseDouble会保留两位小数，导致最后算出来的数据偏差较大
//            double trueWeight1 = Double.parseDouble(df.format(Tweight1 / allweight1));
//            overAllPoint += Double.parseDouble(df.format(trueWeight1 * allsecondPoint));
            //修改后，不提前处理数据
            double trueWeight1 = Tweight1 / allweight1;
            overAllPoint += trueWeight1 * allsecondPoint;
            /*改写统分方法*/


            part2Map.put("point", allsecondPoint);
            part2Map.put("part2InnerList", part2InnerList);
            part2List.add(part2Map);
        }
        overAllPoint = overAllPoint - allExtraPoint;
        overAllPoint=Double.parseDouble(df.format(overAllPoint));
        dataMap.put("overAllPoint", overAllPoint);
        //将总分存到ALLPOINTSAVE中
        int allPointInDB = mapperUtils.getAllpointsaveMapper().getAllPointCountByCheckId(checkId, -1);
        if (allPointInDB != 0) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date1 = new Date(System.currentTimeMillis());
            String lastEditTime = formatter.format(date1);
            mapperUtils.getAllpointsaveMapper().updateAllPoint(checkId, df.format(overAllPoint), -1, lastEditTime);
        } else {
            Allpointsave allpointsave = new Allpointsave();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date1 = new Date(System.currentTimeMillis());
            allpointsave.setNewCreateTime(formatter.format(date1));
            allpointsave.setLastEditTime(formatter.format(date1));
            allpointsave.setCheckId(checkId);
            allpointsave.setNumber(-1);
            allpointsave.setProjectId(projectId);
            allpointsave.setPoint(df.format(overAllPoint));
            mapperUtils.getAllpointsaveMapper().insert(allpointsave);
        }
        //将总分存到CCT表中
        ContractCheckTask contractchecktask = new ContractCheckTask();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date1 = new Date(System.currentTimeMillis());
        contractchecktask.setLastEditTime(formatter.format(date1));
        contractchecktask.setCheckId(checkId);
        contractchecktask.setTotalPoint(String.valueOf(overAllPoint));
        mapperUtils.getContractchecktaskMapper().updateByPrimaryKeySelective(contractchecktask);

        List<ProblemCollectDetail> overallList = parProblemCollectDetailMapper.getAllProblemCollectInfoByCheckId(checkId);
        String overAllLever=" ";
        switch(Integer.parseInt(pointsCalculate.getMaxRiskPoint(overallList))){
            case 4:
                overAllLever="一级隐患";
                break;
            case 3:
                overAllLever="二级隐患";
                break;
            case 2:
                overAllLever="三级隐患";
                break;
            case 1:
                overAllLever="四级隐患";
                break;
        }
        dataMap.put("overAllLever", overAllLever);
        ContractTaskProject contractTaskProjectRiskPoint = new ContractTaskProject();
        contractTaskProjectRiskPoint.setProjectId(projectId);
        contractTaskProjectRiskPoint.setLatestRiskLevel(pointsCalculate.getMaxRiskPoint(overallList));
        contractTaskProjectRiskPoint.setLastEditTime(formatter.format(date1));
        mapperUtils.getContractTaskProjectMapper().updateByPrimaryKeySelective(contractTaskProjectRiskPoint);
        ContractTaskProject newRiskList = mapperUtils.getContractTaskProjectMapper().selectByPrimaryKey(projectId);
        String finishTime = mapperUtils.getContractchecktaskMapper().getFinishTimeByCheckId(checkId);
        if (newRiskList.getCheckTime().equals("") || newRiskList.getCheckTime().compareTo(finishTime) <= 0) {
            try {
                ContractTaskProject contracttaskproject = new ContractTaskProject();
                contracttaskproject.setProjectId(projectId);
                contracttaskproject.setLatestCheckTime(finishTime);
                contracttaskproject.setLastEditTime(formatter.format(date1));
                mapperUtils.getContractTaskProjectMapper().updateByPrimaryKeySelective(contracttaskproject);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        dataMap.put("part2List", part2List);

        //第三部分 问题分布
        List<Object> part3List = new ArrayList<>();
        int allFourthProblem = 0;
        for (int k = 0; k < name1Array.size(); k++) {
            Map<String, Object> part3Map = new HashMap<String, Object>();
            List<Object> part3InnerList = new ArrayList<Object>();
            String pName1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(k)); //通过firstId找到pName1
            part3Map.put("name1", pName1);
            List<Object> secondIdList = parProblemCollectDetailMapper.getSecondId(checkId, pName1);  //获取secondIdList
            String secondIdInfo = JSON.toJSONString(secondIdList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray secondIdInfoArray = JSONArray.parseArray(secondIdInfo);
            //计算第四级的问题总数
            DefaultPieDataset datasetProblemPie = new DefaultPieDataset();
            DefaultCategoryDataset datasetProblemBar = new DefaultCategoryDataset();
            allFourthProblem = this.calculateAllFourthProblem(checkId, secondIdInfoArray, isNew);
            part3Map.put("allProblemNum", allFourthProblem);
            List<Double> percentList = new ArrayList<>();
            List<String> name4List = new ArrayList<>();
            for (int n = 0; n < secondIdInfoArray.size(); n++) {
                int secondId = secondIdInfoArray.getIntValue(n);
                List<ProblemCollectDetail> fourthPoints = parProblemCollectDetailMapper.getFourthPoint(checkId, pName1, secondId);
                String fourthCalculateInfo = JSON.toJSONString(fourthPoints, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray fourthPointsCalculateArray = JSONArray.parseArray(fourthCalculateInfo);
                for (int j = 0; j < fourthPointsCalculateArray.size(); j++) {
                    Map<String, Object> part3InnerMap = new HashMap<String, Object>();
                    JSONObject part3InnerObject = fourthPointsCalculateArray.getJSONObject(j);
                    String name4 = part3InnerObject.getString("pName4");
                    part3InnerMap.put("nom", j + 1);
                    part3InnerMap.put("name4", name4);
                    int fourthProblemCount = parProblemCollectDetailMapper.countFourthProblem(checkId, secondId, name4);
                    part3InnerMap.put("problemNum", fourthProblemCount);
                    String percent = pointsCalculate.caculateToPercent(fourthProblemCount, allFourthProblem);
                    part3InnerMap.put("percent", percent);
                    part3InnerList.add(part3InnerMap);
                    datasetProblemPie.setValue(name4 + ":" + percent, new Double(fourthProblemCount));
                    datasetProblemBar.setValue(fourthProblemCount, "各检查分项", name4);
                }
            }

            try {
                JFreeChart chart = ChartFactory.createPieChart("现场施工问题分布饼图",
                        datasetProblemPie,
                        true,
                        true,
                        false);
                final PiePlot plot = (PiePlot) chart.getPlot();
                //设置旋转角度
                plot.setStartAngle(270);
                //设置图表透明图0.0~1.0范围。0.0为完全透明，1.0为完全不透明。
                plot.setForegroundAlpha(0.90f);
                plot.setInteriorGap(0.02);
                chart.getLegend().setVisible(false);
//                File pieChart = new File("E:\\tencent_File\\1296928795\\FileRecv\\" + dataMap.get("fileDate") + "pieChart.png");
                File pieChart = new File("D:\\whutServer\\generatedCharts\\" + dataMap.get("fileDate") + "pieChart.png");
                ChartUtils.saveChartAsPNG(pieChart, chart, WIDTH, HEIGHT);
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                JFreeChart barChart = ChartFactory.createBarChart("现场施工问题分布直方图",
                        "",
                        "数量",
                        datasetProblemBar,
                        PlotOrientation.VERTICAL,
                        true, true, false);
                CategoryPlot plot = (CategoryPlot) barChart.getPlot();
                plot.getRenderer().setSeriesPaint(0, new Color(5, 87, 232));
                BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
                barRenderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
                barRenderer.setDefaultItemLabelsVisible(true);
                barRenderer.setItemLabelAnchorOffset(-20D);
                barRenderer.setMaximumBarWidth(0.2);
                CategoryAxis categoryAxis = plot.getDomainAxis();
                categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
//                File barChartFile = new File("E:\\tencent_File\\1296928795\\FileRecv\\" + dataMap.get("fileDate") + "barChart.png");
                File barChartFile = new File("D:\\whutServer\\generatedCharts\\" + dataMap.get("fileDate") + "barChart.png");
                ChartUtils.saveChartAsPNG(barChartFile, barChart, WIDTH, HEIGHT);
            } catch (Exception e) {
                e.printStackTrace();
            }
//            part3Map.put("pieChart",MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\" + dataMap.get("fileDate") + "pieChart.png"));
//            part3Map.put("histogram", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\" + dataMap.get("fileDate") + "barChart.png"));
            part3Map.put("pieChart", MDoc.getImageStr("D:\\whutServer\\generatedCharts\\" + dataMap.get("fileDate") + "pieChart.png"));
            part3Map.put("histogram", MDoc.getImageStr("D:\\whutServer\\generatedCharts\\" + dataMap.get("fileDate") + "barChart.png"));

            part3Map.put("part3InnerList", part3InnerList);
            part3List.add(part3Map);
        }
        dataMap.put("part3List", part3List);
//        System.out.println("dataMap:"+dataMap);
        //三.检查问题综述
        List<Object> part4List = new ArrayList<Object>();
        for (int i = 0; i < name1Array.size(); i++) {
            List<Object> part4InnerList = new ArrayList<Object>();
            Map<String, Object> part4Map = new HashMap<String, Object>();
            String pName1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(i));
            System.out.println("pName1" + pName1);
            List<Summary> summaryList = mapperUtils.getSummaryMapper().getSummaryInfo(checkId, name1Array.getIntValue(i));
            String summaryInfo = JSON.toJSONString(summaryList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray summaryInfoArray = JSONArray.parseArray(summaryInfo);
            for (int j = 0; j < summaryInfoArray.size(); j++) {
                Map<String, Object> part4InnerMap = new HashMap<String, Object>();
                JSONObject part4InnerObject = summaryInfoArray.getJSONObject(j);
                String part4pNname4 = parSystemMapper.getName4ByName4Id(part4InnerObject.getIntValue("fourthId"));
                part4InnerMap.put("pName4", part4pNname4);
                part4InnerMap.put("summary", part4InnerObject.getString("summary"));
                part4InnerList.add(part4InnerMap);
            }
            if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                part4Map.put("name1", "安全");
            } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                part4Map.put("name1", "质量");
            } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                part4Map.put("name1", "管理");
            }
            part4Map.put("part4InnerList", part4InnerList);
            part4List.add(part4Map);
        }
        dataMap.put("part4List", part4List);
        //四、（一）风险隐患分布表
        int txNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "提醒");
        int oneNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "1");
        int twoNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "2");
        int threeNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "3");
        int fourNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "4");
        int allProblemNum = txNum + oneNum + twoNum + threeNum + fourNum;
        dataMap.put("txNum", txNum);
        dataMap.put("oneNum", oneNum);
        dataMap.put("twoNum", twoNum);
        dataMap.put("threeNum", threeNum);
        dataMap.put("fourNum", fourNum);
        dataMap.put("allProblemNum", allProblemNum);
        String txPercent = pointsCalculate.caculateToPercent(txNum, allProblemNum);
        String onePercent = pointsCalculate.caculateToPercent(oneNum, allProblemNum);
        String twoPercent = pointsCalculate.caculateToPercent(twoNum, allProblemNum);
        String threePercent = pointsCalculate.caculateToPercent(threeNum, allProblemNum);
        String fourPercent = pointsCalculate.caculateToPercent(fourNum, allProblemNum);

        dataMap.put("txPercent", txPercent);
        dataMap.put("onePercent", onePercent);
        dataMap.put("twoPercent", twoPercent);
        dataMap.put("threePercent", threePercent);
        dataMap.put("fourPercent", fourPercent);
        //四、（二）风险隐患问题汇总表
        List<Object> partProblemList = new ArrayList<Object>();
        for (int i = 0; i < name1Array.size(); i++) {
            List<Object> partProblemName1List = new ArrayList<Object>();
            Map<String, Object> partProblemMap = new HashMap<String, Object>();
            String pName1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(i));
            List<Integer> problemName4List = parProblemCollectDetailMapper.getAllName4ByName1(checkId, pName1);
            String problemName4Info = JSON.toJSONString(problemName4List, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray problemName4Array = JSONArray.parseArray(problemName4Info);
            for (int k = 0; k < problemName4Array.size(); k++) {
                List<ProblemCollectDetail> partProblemDetailList = parProblemCollectDetailMapper.getAllFourthInfo(checkId, problemName4Array.getIntValue(k));
                String partProblemDetailInfo = JSON.toJSONString(partProblemDetailList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray partProblemDetailArray = JSONArray.parseArray(partProblemDetailInfo);
                String problemName4 = parSystemMapper.getName4ByName4Id(problemName4Array.getIntValue(k));
                for (int j = 0; j < partProblemDetailArray.size(); j++) {
                    Map<String, Object> partProblemName1Map = new HashMap<String, Object>();
                    JSONObject partProblemObject = partProblemDetailArray.getJSONObject(j);
                    String problemDescription = partProblemObject.getString("problemDescription");
                    String riskPoint = partProblemObject.getString("riskPoint");
                    if (partProblemObject.getString("isRemark").equals("N")) {
                        partProblemName1Map.put("problemDescription", problemDescription);
                    } else if (partProblemObject.getString("isRemark").equals("Y")) {
                        partProblemName1Map.put("problemDescription", partProblemObject.getString("remark"));
                    }
                    String riskLever=" ";
                    switch(Integer.parseInt(riskPoint)){
                        case 4:
                            riskLever="一级隐患";
                            break;
                        case 3:
                            riskLever="二级隐患";
                            break;
                        case 2:
                            riskLever="三级隐患";
                            break;
                        case 1:
                            riskLever="四级隐患";
                            break;
                    }
                    partProblemName1Map.put("riskPoint", riskLever);
                    partProblemName1Map.put("name4", problemName4);
                    partProblemName1List.add(partProblemName1Map);
                }
            }
            if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                partProblemMap.put("name1", "安全");
            } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                partProblemMap.put("name1", "质量");
            } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                partProblemMap.put("name1", "管理行为");
            }
            partProblemMap.put("partProblemName1List", partProblemName1List);
            partProblemList.add(partProblemMap);
        }
        dataMap.put("partProblemList", partProblemList);
        //第二部分，各部分工程检查情况
        String section2pName1 = "";
        List<Object> section2List = new ArrayList<Object>();
        for (int b = 0; b < name1Array.size(); b++) {
            Map<String, Object> section2Name1Map = new HashMap<String, Object>();
            List<Object> section2name1List = new ArrayList<Object>();
            String section2name1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(b));
            if (section2name1.equals("安全检查")||section2name1.equals("新安全检查")) {
                section2pName1 = "安全问题";
            } else if (section2name1.equals("质量检查")||section2name1.equals("新质量检查")) {
                section2pName1 = "质量问题";
            } else if (section2name1.equals("管理行为")||section2name1.equals("新管理行为")) {
                section2pName1 = "管理体系及管理动作";
            }
            section2Name1Map.put("section2pName1", section2pName1);
            List<Integer> section2Name4Info = parProblemCollectDetailMapper.getAllName4ByName1(checkId, section2name1);
            String section2Name44 = JSON.toJSONString(section2Name4Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray section2Name4Array = JSONArray.parseArray(section2Name44);
            for (int w = 0; w < section2Name4Array.size(); w++) {
                Map<String, Object> section2Name4Map = new HashMap<String, Object>();
                List<Object> section2Name4List = new ArrayList<Object>();
                int section2Name4Id = section2Name4Array.getIntValue(w);
                String section2Name4 = parSystemMapper.getName4ByName4Id(section2Name4Id);
                List<ProblemCollectDetail> section2Name6Info = parProblemCollectDetailMapper.getAllName6InfoByName4(checkId, section2Name4Id, section2name1);
                String section2Name66 = JSON.toJSONString(section2Name6Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray section2Name6Array = JSONArray.parseArray(section2Name66);
                for (int c = 0; c < section2Name6Array.size(); c++) {
                    Map<String, Object> section2Name6Map = new HashMap<String, Object>();
                    List<Object> picList = new ArrayList<Object>();
                    JSONObject section2Name6Object = section2Name6Array.getJSONObject(c);
                    section2Name6Map.put("section2pName6No", c + 1);
                    section2Name6Map.put("section2pName6", section2Name6Object.getString("pName6"));
                    section2Name6Map.put("section2pName5", section2Name6Object.getString("pName5"));
                    String section2RiskLevel=" ";
                    switch(Integer.parseInt(section2Name6Object.getString("riskPoint"))){
                        case 4:
                            section2RiskLevel="一级隐患";
                            break;
                        case 3:
                            section2RiskLevel="二级隐患";
                            break;
                        case 2:
                            section2RiskLevel="三级隐患";
                            break;
                        case 1:
                            section2RiskLevel="四级隐患";
                            break;
                    }
                    section2Name6Map.put("section2RiskLevel", section2RiskLevel);
                    section2Name6Map.put("section2CheckPart", section2Name6Object.getString("checkPart"));
                    section2Name6Map.put("section2ProblemNum", section2Name6Object.getString("problemQua"));
                    if (section2Name6Object.getString("isRemark").equals("N")) {
                        section2Name6Map.put("section2problemDescription", section2Name6Object.getString("problemDescription"));
                    } else if (section2Name6Object.getString("isRemark").equals("Y")) {
                        section2Name6Map.put("section2problemDescription", section2Name6Object.getString("remark"));
                    }
                    section2Name6Map.put("section2normsProvison", section2Name6Object.getString("normsProvison"));
                    section2Name6Map.put("section2suggestion", section2Name6Object.getString("suggestion"));
                    String section2picPath = section2Name6Object.getString("picPath");
                    String picName = section2Name6Object.getString("picName");
                    JSONArray ja = JSONArray.parseArray(picName);
                    if (ja.size() == 0) {
//                        String s = MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png");
                        String s = MDoc.getImageStr("D:\\whutServer\\generatedCharts\\noPic.png");
                        picList.add(s);
                    } else {
                        for (int o = 0; o < ja.size(); o++) {

                            String s="";
                            if("prod".equals(profiles.getActives())){
                                s = MDoc.getImageStr(section2picPath + ja.getString(o));
                            }
                            //String s = MDoc.getImageStr(section2picPath + ja.getString(o));
                            //String s = MDoc.getImageStr("D:\\whutServer\\generatedCharts\\test.png");
                            //String imgFilePath = "";
//                            if (!MDoc.isFoundImageStr(imgFilePath)) {
//                                imgFilePath = "D:\\whutServer\\generatedCharts\\test.png";
//                            }
                            //String s = MDoc.getImageStr(imgFilePath);
//                            String s = MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png");
                            picList.add(s);
                        }
                    }
                    section2Name6Map.put("picList", picList);
                    section2Name4List.add(section2Name6Map);

                }
                String section2pName4No='('+ReportCommonFunc.num2Chinese(w+1)+')';
                section2Name4Map.put("section2pName4No", section2pName4No);
                section2Name4Map.put("section2pName4", section2Name4);
                section2Name4Map.put("section2Name4List", section2Name4List);
                section2name1List.add(section2Name4Map);
            }
            section2Name1Map.put("section2Name1List", section2name1List);
            section2List.add(section2Name1Map);
        }
        dataMap.put("section2List", section2List);
        MDoc mdoc = new MDoc();
        String path = FileUtil.getServerFolderPath();
        File f1 = new File(path, "doc");
        if (!f1.exists()) {
            f1.mkdirs();
        }
        //System.out.println("dataMap:"+dataMap);
        String result = "";
//        mdoc.createDoc(dataMap, "E:\\tencent_File\\1296928795\\FileRecv\\yirui\\" + String.valueOf(dataMap.get("projectName")).replace('#','号')+"建设局综合检查报告"+dataMap.get("fileDate") + ".doc", "ftl\\constructionMulCheckReport.ftl");
//        MDoc.docToDocx("E:\\tencent_File\\1296928795\\FileRecv\\yirui\\" + String.valueOf(dataMap.get("projectName")).replace('#','号')+"建设局综合检查报告"+dataMap.get("fileDate") + ".doc", "E:\\tencent_File\\1296928795\\FileRecv\\yirui" + String.valueOf(dataMap.get("projectName")).replace('#','号')+"建设局综合检查报告"+dataMap.get("fileDate") + ".doc");
//        result = "E:\\tencent_File\\1296928795\\FileRecv\\yirui\\" + String.valueOf(dataMap.get("projectName")).replace('#','号')+"建设局综合检查报告"+dataMap.get("fileDate") + ".doc";
        mdoc.createDoc(dataMap, path + "\\doc\\" + String.valueOf(dataMap.get("projectName")).replace('#', '号') + "建设局综合检查报告" + dataMap.get("fileDate") + ".doc", "ftl\\constructionMulCheckReport.ftl");
        //MDoc.docToDocx("D:\\whutServer\\apache-tomcat-8.5.41\\webapps\\ROOT\\doc\\" + String.valueOf(dataMap.get("projectName")).replace('#','号')+"建设局综合检查报告"+dataMap.get("fileDate") + ".doc", "D:\\whutServer\\apache-tomcat-8.5.41\\webapps\\ROOT\\doc\\" + String.valueOf(dataMap.get("projectName")).replace('#','号')+"建设局综合检查报告"+dataMap.get("fileDate") + ".doc");
        result = mapperUtils.getUrlProperties().getAddress() + "/doc/" + String.valueOf(dataMap.get("projectName")).replace('#', '号') + "建设局综合检查报告" + dataMap.get("fileDate") + ".doc";
        return result;



    }

    public void initWordTheme() {
        StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
        //设置标题字体
        standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
        //设置图例的字体
        standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
        //设置轴向的字体
        standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
        //应用主题样
        ChartFactory.setChartTheme(standardChartTheme);
    }

    public void initWordDate(Map<String, Object> dataMap) {
        Date date = new Date();
        dataMap.put("day", new SimpleDateFormat("dd").format(date));
        dataMap.put("month", new SimpleDateFormat("MM").format(date));
        dataMap.put("year", new SimpleDateFormat("yyyy").format(date));
        dataMap.put("fileDate", new SimpleDateFormat("yyyyMMddhhmmss").format(date));
    }

    private double calculateAllWeight4Func(int checkId, JSONObject part2InnerObject, Integer taskId, boolean isNew) {
        double allweight4 = 0;
        List<ProblemCollectDetail> countFourthWeight = parProblemCollectDetailMapper.getAllFourthInfoMXTQ(checkId, part2InnerObject.getIntValue("thirdId"));
        for (int v = 0; v < countFourthWeight.size(); v++) {
            double Tweight4 = 0;
            int fourthId = countFourthWeight.get(v).getFourthId();
            //更改取权重的表
            String newWeight4 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(fourthId, taskId);
            if (StringUtils.isNotBlank(newWeight4)) {
                Tweight4 = pointsCalculate.getPercentInstance(newWeight4);
            } else {
                String trueweight4 = parSystemMapper.getWeight3ByThirdId(fourthId);
                Tweight4 = pointsCalculate.getPercentInstance(trueweight4);
            }
            allweight4 += Tweight4;
        }
        return allweight4;
    }

    private List<Double> calculatePoint6Func(JSONArray sixthPointsArray, int checkId, boolean isNew) {
        double calculatePoint66 = 0;
        double calculatePoint6 = 0;
        double calculateTruePoint = 0;
        for (int y = 0; y < sixthPointsArray.size(); y++) {
            JSONObject sixPointObject = sixthPointsArray.getJSONObject(y);
            int deductSixthId = sixPointObject.getIntValue("sixthId");
            System.out.println("sixId:" + deductSixthId);
            float deductPointsSumFloat = parProblemCollectDetailMapper.getdeductSum(checkId, deductSixthId);
            double deductPointsSum = Double.valueOf(String.valueOf(deductPointsSumFloat));
            double truePoint = Double.parseDouble(sixPointObject.getString("point6"));
            System.out.println("各类point:" + deductPointsSum + " " + truePoint);
            if (truePoint <= deductPointsSum) {
                calculatePoint66 = 0;
            } else {
                calculatePoint66 = truePoint - deductPointsSum;
            }
            calculateTruePoint += truePoint;  //体系分数
            calculatePoint6 += calculatePoint66;  //得分总和
        }
        List<Double> calculatePointList = new ArrayList<>();
        calculatePointList.add(calculateTruePoint);
        calculatePointList.add(calculatePoint6);
        System.out.println("计算point6:" + calculatePointList);
        return calculatePointList;
    }

    private double calculateNoProblemPointFunc(int checkId, JSONObject part2InnerObject,boolean isNew) {
        double noProblemPoint = 0;
        List<Object> noProblemSixthIdList = mapperUtils.getUncheckeditemsMapper().getNoProblemSixthId(checkId, part2InnerObject.getIntValue("fourthId"));
        String noProblemSixthIdInfo = JSON.toJSONString(noProblemSixthIdList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray noProblemSixthArray = JSONArray.parseArray(noProblemSixthIdInfo);
        for (int m = 0; m < noProblemSixthArray.size(); m++) {
            int noProblemSixthId = noProblemSixthArray.getIntValue(m);
            double noProblem = Double.parseDouble(parSystemMapper.getPoint4ByPoint4Id(noProblemSixthId));
            noProblemPoint += noProblem;
        }
        return noProblemPoint;
    }

    private String getCheckItemPointAndUpdateAllPointSave(int checkId, int part2FourthId, int projectId, double checkItemPoint, DecimalFormat df) {
        List<ProblemCollectDetail> checkItemCalcuList = parProblemCollectDetailMapper.getAllFourthInfo(checkId, part2FourthId);
        String maxFourthRiskPoint = pointsCalculate.getMaxRiskPoint(checkItemCalcuList);
        int maxFourthRiskPointNum = parProblemCollectDetailMapper.getRiskPointCount(checkId, part2FourthId, maxFourthRiskPoint);
        double limitFourhPoint = Double.parseDouble((mapperUtils.getPointlimitMapper().getLimitPointByInfo(String.valueOf(maxFourthRiskPointNum), maxFourthRiskPoint)) == null ? "100" : mapperUtils.getPointlimitMapper().getLimitPointByInfo(String.valueOf(maxFourthRiskPointNum), maxFourthRiskPoint));
        if (checkItemPoint > limitFourhPoint) {
            checkItemPoint = limitFourhPoint;
        }
        String s = df.format(checkItemPoint);
        int allPointSaveFourthPointCount = mapperUtils.getAllpointsaveMapper().getAllPointCountByCheckId(checkId, part2FourthId);
        if (allPointSaveFourthPointCount != 0) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date1 = new Date(System.currentTimeMillis());
            String lastEditTime = formatter.format(date1);
            mapperUtils.getAllpointsaveMapper().updateAllPoint(checkId, s, part2FourthId, lastEditTime);
        } else {
            Allpointsave allpointsave = new Allpointsave();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date1 = new Date(System.currentTimeMillis());
            allpointsave.setNewCreateTime(formatter.format(date1));
            allpointsave.setLastEditTime(formatter.format(date1));
            allpointsave.setProjectId(projectId);
            allpointsave.setCheckId(checkId);
            allpointsave.setNumber(part2FourthId);
            allpointsave.setPoint(s);
            mapperUtils.getAllpointsaveMapper().insert(allpointsave);
        }

        return s;
    }
    private int calculateAllFourthProblem(int checkId, JSONArray secondIdInfoArray, boolean isNew) {
        int allFourthProblem = 0;
        int temp = 0;
        for (int i = 0; i < secondIdInfoArray.size(); i++) {
            int secondId = secondIdInfoArray.getIntValue(i);
            temp = parProblemCollectDetailMapper.countProblemBySecondId(checkId, secondId);
            allFourthProblem += temp;
        }
        return allFourthProblem;
    }
    private String getPart2InnerListweight4(int checkId, int part2ThirdId, double weight3, double weight4, double allweight4) {
        List<Object> fourthCountList = parProblemCollectDetailMapper.getFourthCountList(checkId, part2ThirdId);
        String fourthCountInfo = JSON.toJSONString(fourthCountList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray fourthCountInfoArray = JSONArray.parseArray(fourthCountInfo);
        int countFourthId = fourthCountInfoArray.size();
        return pointsCalculate.double2ToPercent(weight3, allweight4 / weight4);
    }

}
